#!/usr/bin/gnuplot

reset

#set style line 1 lt 2 lc rgb '#000000' lw 1 # black
#set style line 2 lt 1 lc rgb '#9400d3' lw 1 # purple
#set style line 3 lt 1 lc rgb '#ff4500' lw 1 # orange-1
#set style line 4 lt 1 lc rgb '#006400' lw 1 # green
#set style line 5 lt 1 lc rgb '#ffa500' lw 1 # yellow
#set style line 6 lt 1 lc rgb '#0000ff' lw 1 # blue
#set style line 7 lt 1 lc rgb '#800000' lw 1 # brown
#set style line 8 lt 1 lc rgb '#ff0000' lw 1 # orange-2

# color definitions
set border linewidth 1.5
set style line  1 lt 2 lc rgb '#000000' lw 1 # black

set style line  4 lt 1 lc rgb '#ffa500' lw 1 # green
set style line  6 lt 1 lc rgb '#0000ff' lw 1 # blue
set style line  8 lt 1 lc rgb '#ff0000' lw 1 # orange-2
set style line 10 lt 1 lc rgb '#9400d3' lw 1 # purple

set style line 11 lt 2 lc rgb '#000000' lw 1 # black


b2 = b1 = 0
back(x) = (b2 = b1, b1 = x)
OOA(x) = (back(x), $0 > 0 ? (log(b2/b1)/log(2)) : 1/0)
const(x) = 2

#-------------------------------------------------------------------------------------

set terminal wxt 1 size 900,400 enhanced dashed

set multiplot layout 1,2 title 'Steady 1D heat conduction'
set xlabel "Length (m)"
set ylabel "Temperature (K)"
set xrange [*:*]
set yrange [*:*]

set key reverse inside left bottom

set title
plot 'POST_TG.dat' index  3 using 1:2 w lines ls 11 lt 1 title 'Analytic', \
     'POST_TG.dat' index  0 every  1 using 1:3 w points ls  4 title '  8 mesh', \
     'POST_TG.dat' index  1 every  2 using 1:3 w points ls  6 title ' 16 mesh', \
     'POST_TG.dat' index  2 every  4 using 1:3 w points ls  8 title ' 32 mesh', \
     'POST_TG.dat' index  3 every  8 using 1:3 w points ls 10 title ' 64 mesh'

set ylabel "abs error (K)"
set logscale y
set xrange [*:*]
set yrange [*:*]

set title
plot 'POST_TG.dat' index  0 every  1 using 1:4 w points ls  4 notitle, \
     'POST_TG.dat' index  1 every  2 using 1:4 w points ls  6 notitle, \
     'POST_TG.dat' index  2 every  4 using 1:4 w points ls  8 notitle, \
     'POST_TG.dat' index  3 every  8 using 1:4 w points ls 10 notitle

unset logscale x
unset multiplot
